package com.abyss.sink;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.core.fs.FileSystem;

/**
 * 将数据写出到本地文件和HDFS中
 */
public class SinkToFileDemo {
    public static void main(String[] args) throws Exception {
        // 1. Env
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        // 2. Source
        DataSource<Long> source = env.generateSequence(1, 10);

        // 3. Sink to Local file
        source.writeAsText("/Users/abyss/Dev/toys/flink/H-flink-learn/src/main/resources/SinkToFileDemo.txt", FileSystem.WriteMode.OVERWRITE).setParallelism(1);

        // 4. Sink to HDFS file
        source.writeAsText("hdfs://node1:8000/test/SinkToFileDemo.txt").setParallelism(1);

        // 3.3 Sink to local csv file
        source.writeAsCsv(
                "data/output/xxx3csv",
                "\n",
                ",",
                FileSystem.WriteMode.OVERWRITE
                );

        // 5. 提交任务
        env.execute();
    }
}
